#ifdef _WIN32
// Windows does not have setuid/setgid, so we can add a dummy implementation for testing
#include <cstdio>
inline int setuid(int) { printf("setuid is not available on Windows.\n"); return 0; }
inline int setgid(int) { printf("setgid is not available on Windows.\n"); return 0; }
inline int getuid() { return 0; }
inline int getgid() { return 0; }
inline void handle_error() { printf("An error occurred.\n"); }
#else
#include <unistd.h> // For setuid, setgid, getuid, getgid
#include <stdio.h>  // For printf
inline void handle_error() { printf("An error occurred.\n"); }
#endif

namespace security_SetgidSetuidOrder {
    void test1() {
        // ...
        // end of section with elevated privileges
        // reset privileges (user and group) to normal user
        if (setuid(getuid()) != 0) {
            handle_error();
            return;
        }
        if (setgid(getgid()) != 0) { // warning: A 'setgid(getgid())' call following a 'setuid(getuid())' call is likely to fail
            handle_error();
            return;
        }
        // user-ID and group-ID are reset to normal user now
        // ...
    }
}
